package net.melon.sysres.provider;

import java.text.MessageFormat;
import java.util.Locale;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

import net.esj.basic.core.engine.support.message.AbstractMessageProvider;
import net.melon.sysres.manager.SystemManager;
import net.melon.sysres.pojo.ExceptionCode;

@Singleton
@Named
public class ExceptionCodeMessageProvider extends AbstractMessageProvider {

	private SystemManager systemManager;
	
	@Override
	protected MessageFormat resolveCode(String sourceName, String code,
			Locale locale) {
		ExceptionCode ec = systemManager.getExceptionCode(code, locale);
		if(ec!=null){
			return new MessageFormat(ec.getMessage(), locale);
		}
		return null;
	}

	@Inject
	public void setSystemManager(SystemManager systemManager) {
		this.systemManager = systemManager;
	}

	@Override
	public int order() {
		return 1;
	}

}
